package com.kukudexin;

import java.math.BigDecimal;

/**
 * @author: 酷酷的鑫
 * @Date: 2021/12/8 17:47
 * @description:
 */
public class Test15 {
    public static void main(String[] args) {
        Integer [] intArr = {65,32,98,4,12};
        MyClassImpl<Integer> obj1 = new MyClassImpl<>(intArr);
        System.out.println( obj1.min() );

        Character [] charArr = {'a','h','y','x'};
        MyClassImpl<Character> obj2 = new MyClassImpl<>(charArr);
        System.out.println( obj2.min());

        BigDecimal [] bigDecimalArr = {BigDecimal.valueOf(1),BigDecimal.valueOf(2),BigDecimal.valueOf(3)};
        MyClassImpl<BigDecimal> obj3 = new MyClassImpl<>(bigDecimalArr);
        System.out.println( obj3.min());
    }
}

interface GenericMin<T extends Comparable<T> >{
    T min();    //定义抽象方法返回最小值
}


class MyClassImpl<T extends Comparable<T>> implements GenericMin<T> {
    private  T [] values;   //声明数组
    //通过构造方法给数组初始化
    public MyClassImpl(T[] values) {
        this.values = values;
    }
    @Override
    public T min() {
        T minvalue = values[0];     //定义变量保存最小值
        for (int i = 0; i < values.length; i++) {
            if(values[i].compareTo(minvalue)<0){
                minvalue = values[i];
            }
        }
        return minvalue;
    }
}